//
//  ImageUnit.m
//  NetworkTaxiDriver
//
//  Created by thinkjoy on 16/9/22.
//  Copyright © 2016年 Thinkjoy_RS. All rights reserved.
//

#import "ImageUnit.h"

@implementation ImageUnit

/**
 *  image转化为base64字符串,CGFloat compressionQuality
 compression is 0(most)..1(least)
 */
+ (NSString *)imageToBase64Str:(UIImage *)image compressionQuality:(CGFloat)compressionQuality
{
    if (compressionQuality<0) {
        compressionQuality=0;
    }else if (compressionQuality>1.0){
        compressionQuality=1;
    }
    NSData *data = UIImageJPEGRepresentation(image, compressionQuality);
    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return encodedImageStr;
}

/**
 *  base64字符串转化为image
 */
+ (UIImage *)base64StrToImage:(NSString *)imgStr
{
    NSData *_decodedImageData   = [[NSData alloc] initWithBase64EncodedString:imgStr options:NSDataBase64DecodingIgnoreUnknownCharacters];;
    UIImage *_decodedImage      = [UIImage imageWithData:_decodedImageData];
    return _decodedImage;
}


@end
